<?php

namespace App\Http\Controllers\Backend;

use App\Comments;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $articles=Comments::orderBy('created_at', 'desc')->paginate(10);
        return view('backend.comment.index')->with('articles',$articles);
    }


    public function recomment(){
        $id=\Input::get('id');
        $comment=Comments::find($id);
        return view('backend.comment.recomment')->with('comment',$comment);
    }

    public function dorecomment(){
        $id=\Input::get('id');
        $is_admin=\Input::get('is_admin');
        $Comments=Comments::find($id);
        $Comments->is_admin=$is_admin;
        $Comments->save();
        $data=array();
        $data['type']='s';
        $data['message']='回复成功';
        return redirect()->back()->with('message',$data);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy()
    {
        $id=\Input::get('id');
        Comments::destroy($id);
        $data=array();
        $data['type']='s';
        $data['message']='删除成功';
        return redirect()->back()->with('message',$data);
    }
}
